<?php
namespace app\backstage\validate;

use think\Validate;

class Withdrawal extends Validate
{
    protected $rule = [
        'id'            => 'require|gt:0',
        'money'         => 'require|gt:0|checkMoney',
        'bank_id'       => 'require|gt:0',
        'settlement_date' => 'require',
    ];

    protected $message  =   [
        'id.require'              => '信息ID不能为空',
        'id.gt'                   => '信息ID不能为空',
        'money.require'           => '提现金额不能为空',
        'money.gt'                => '提现金额不能小于1',
        'bank_id.require'         => '请选择提现银行卡',
        'bank_id.gt'              => '请选择提现银行卡',
        'settlement_date.require' => '结算日期不能为空',
    ];

    protected $scene = [
        'add'   => ['money','settlement_date'],
        'info'  => ['id'],
    ];

    //校验金额合法性
    protected function checkMoney($value)
    {
        if($value > 1000000)
        {
            return '提现金额单笔不能超过100万';
        }

        if($value < 300)
        {
            return '提现金额单笔不能小于300元';
        }

        return true;
    }
}